package cn.edu.nju.storage;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class StoreDataProvider {
	private static StoreDataProvider provider;
	private Activity activity;
	
	public static StoreDataProvider getInstance(Activity activity){
		if(provider == null){
			provider = new StoreDataProvider(activity);
		}
		return provider;
	}
	
	private StoreDataProvider(Activity activity){
		this.activity = activity;
	}
	
	//If not existed, return -1
	public long getUserId(){
		SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
		long id = sharedPreferences.getLong("id", -1);
		return id;
	}
	
	/**
	 * if have the default user return its name, else return NULL
	 * @return the user name or NULL
	 */
	public String getUserName(){
		SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
		String name = sharedPreferences.getString("recent_user_name", "none");
		if (name.equals(new String("none"))) {
			return null;
		}
		return name;
	}
}
